/* 
 * File: AndroidInput
 * Created: 13-JUN-2011
 * Author: Colin Gall-McDaid
 * 
 * Description: Android implemenation of the Input interface. Ties together all the
 * different input handlers.
 */
package com.gallsoft.games.framework.impl;

import java.util.List;

import android.content.Context;
import android.os.Build.VERSION;
import android.view.View;

import com.gallsoft.games.framework.Input;


public class AndroidInput implements Input {

    private AccelerometerHandler accelHandler;
    private KeyboardHandler keyHandler;
    private TouchHandler touchHandler;
    
    /**
     * Constructor.
     * @param context
     * @param view
     * @param scaleX
     * @param scaleY
     */
    public AndroidInput(Context context, View view, float scaleX, float scaleY) {
        accelHandler = new AccelerometerHandler(context);
        keyHandler = new KeyboardHandler(view);
        
        // Check if device supports multi-touch or not
        if (Integer.parseInt(VERSION.SDK) < 5)
            touchHandler = new SingleTouchHandler(view, scaleX, scaleY);
        else
            touchHandler = new MultiTouchHandler(view, scaleX, scaleY);
    }
    
    /**
     * Check if a key has been pressed
     * 
     * @return true or false
     */
    public boolean isKeyPressed(int keyCode) {
        return keyHandler.isKeyPressed(keyCode);
    }

    /**
     * Check if a pointer is touching the screen
     * 
     * @return true or false
     */
    public boolean isTouchDown(int pointer) {
        return touchHandler.isTouchDown(pointer);
    }

    /**
     * Get x coord of pointer
     * 
     * @return x coordinate
     */
    public int getTouchX(int pointer) {
        return touchHandler.getTouchX(pointer);
    }

    /**
     * Get y coord of pointer
     * 
     * @return y coordinate
     */
    public int getTouchY(int pointer) {
        return touchHandler.getTouchY(pointer);        
    }

    /**
     * Get x axis acceleration
     * 
     * @return x axis acceleration
     */
    public float getAccelX() {
        return accelHandler.getAccelX();
    }

    /**
     * Get y axis acceleration
     * 
     * @return y axis acceleration
     */
    public float getAccelY() {
        return accelHandler.getAccelY();
    }

    /**
     * Get z axis acceleration
     * 
     * @return z axis acceleration
     */
    public float getAccelZ() {
        return accelHandler.getAccelZ();
    }

    /**
     * Get list of key events
     * 
     * @return list of key events
     */
    public List<KeyEvent> getKeyEvents() {
        return keyHandler.getKeyEvents();
    }

    /**
     * Get list of touch events
     * 
     * @return list of touch events
     */
    public List<TouchEvent> getTouchEvents() {
        return touchHandler.getTouchEvents();
    }

}
